/*
 *    Copyright (c) 2018-2025, lengleng All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice,
 * this list of conditions and the following disclaimer.
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the distribution.
 * Neither the name of the pig4cloud.com developer nor the names of its
 * contributors may be used to endorse or promote products derived from
 * this software without specific prior written permission.
 * Author: lengleng (wangiegie@gmail.com)
 */

package com.songlin.houxin.admin.controller;

import com.pig4cloud.plugin.excel.annotation.ResponseExcel;
import com.songlin.houxin.admin.api.dto.*;
import com.songlin.houxin.admin.api.vo.BasePageVO;
import com.songlin.houxin.admin.api.vo.ChannelStatisticVO;
import com.songlin.houxin.admin.api.vo.ChannelVO;
import com.songlin.houxin.admin.service.ChannelService;
import com.songlin.houxin.common.core.util.R;
import com.songlin.pig.common.log.annotation.SysLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 渠道表
 *
 * @author pig code generator
 * @date 2022-03-05 23:31:25
 */
@Validated
@RestController
@RequiredArgsConstructor
@RequestMapping("/channel")
@Api(value = "channel", tags = "渠道表管理")
public class ChannelController {

    private final ChannelService channelService;

    /**
     * 新增渠道表
     *
     * @param dto 渠道表
     * @return R
     */
    @PostMapping(value = "/queryChannelStatisticInfo")
    public R<BasePageVO<ChannelStatisticVO>> queryChannelStatisticInfo(@RequestBody ChannelStatistiDTO dto) {
        return R.ok(channelService.queryChannelStatisticInfo(dto));
    }

    @ApiOperation(value = "保存渠道信息", notes = "保存渠道信息")
    @SysLog("保存渠道信息")
    @PostMapping(value = "/saveChannel")
    public R<Void> saveChannel(@RequestBody ChannelSaveDTO dto) {
        channelService.saveChannel(dto);
        return R.ok();
    }


    @PostMapping(value = "/updateChannel")
    public R<Void> updateChannel(@RequestBody ChannelUpdateDTO dto) {
        channelService.updateChannel(dto);
        return R.ok();
    }


    @PostMapping(value = "/queryChannelList")
    public R<BasePageVO<ChannelVO>> queryChannelList(@RequestBody ChannelListDTO dto) {
        return R.ok(channelService.queryChannelList(dto));
    }

    @PostMapping(value = "/deleteBatchChannel")
    public R<Void> deleteBatchChannel(@RequestBody ChannelDeleteDTO dto) {
        channelService.deleteBatchChannel(dto);
        return R.ok();
    }

    /**
     * 获得一级和二级的树形数据
     *
     * @return R
     */
    @GetMapping("/listSelectTree")
    public R listSelectTree() {
        return R.ok(channelService.listSelectTree());
    }

    @ResponseExcel(name = "渠道统计信息")
    @GetMapping(value = "/exportChannelStatisticInfo")
    public List<ChannelStatisticVO> exportChannelStatisticInfo( ChannelStatistiDTO dto) {
        return channelService.exportChannelStatisticInfo(dto);
    }

}
